//
//  SLTabBarDelegate.m
//  CustomTabBarTransition
//
//  Created by 朱志佳 on 2019/4/4.
//  Copyright © 2019 朱志佳. All rights reserved.
//

#import "SLTabBarDelegate.h"
#import "SlideAnimationController.h"

@implementation SLTabBarDelegate

- (instancetype)init
{
    self = [super init];
    if (self) {
        _interactive = false;
        _interactionController = [[UIPercentDrivenInteractiveTransition alloc] init];
    }
    return self;
}



- (nullable id <UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController
                     animationControllerForTransitionFromViewController:(UIViewController *)fromVC
                                                       toViewController:(UIViewController *)toVC  NS_AVAILABLE_IOS(7_0){
    CGFloat fromIndex = [tabBarController.viewControllers indexOfObject:fromVC];
    CGFloat toIndex = [tabBarController.viewControllers indexOfObject:toVC];
    NSInteger tbChangeDirection = toIndex < fromIndex ? TransitionTypeLeft : TransitionTypeRight;
    tbChangeDirection = toIndex < fromIndex ? TransitionTypeDismisssal : TransitionTypePresentation;
    SlideAnimationController *slideAnimationController = [[SlideAnimationController alloc] init];
    slideAnimationController.transitionType = tbChangeDirection;
    return slideAnimationController;
    
}

- (nullable id <UIViewControllerInteractiveTransitioning>)tabBarController:(UITabBarController *)tabBarController
                               interactionControllerForAnimationController: (id <UIViewControllerAnimatedTransitioning>)animationController NS_AVAILABLE_IOS(7_0){
    NSLog(@"%@##%@",NSStringFromClass([self class]),NSStringFromSelector(_cmd));
    return _interactive ? _interactionController : nil;
}

@end
